import Vue from "vue"
import VueRouter from "vue-router"
import Home from "../views/Home/Home.vue"
import ShopList from "@/views/ShopList/ShopList"
import Login from "@/views/Login/Login.vue"
import Cart from "@/views/Cart/Cart.vue"
import My from "@/views/My/My.vue"
import MyInformation from "@/views/My/MyInformation"
import Mypop from "@/components/common/Mypop"
import Wave from "@/components/specialeffect/Wave"
import Upload from "@/views/My/Upload"
import MyShop from "@/views/Myshop/MyShop"
import UploadCommoditiesd from "@/views/Myshop/UploadCommoditiesd"
import GoodsDetail from "@/views/GoodsDetail/GoodsDetail"
import Attesation from "@/views/My/Attesation"
import Search from "@/views/Search/Search"
import ShopAddress from "@/views/ShopAddress/ShopAddress"
import AddAddress from "@/views/ShopAddress/AddAddress"
import PaySuccess from "@/views/Cart/PaySuccess"
import Order from "@/views/Order/Order"
import GoTalk from "@/views/GoTalk/GoTalk"
import TakePhoto from "@/views/My/TakePhoto"
import ToBeShipped from "@/views/ToBeShipped"
import GoodsDetailList from "@/views/GoodsDetail/GoodsDetailList"
import Face from "@/views/Login/Face"
import FeedBack from "@/views/My/FeedBack"
import OnlineShop from "@/views/Myshop/OnlineShop"
import News from "@/views/News/News"
import NewsDetail from "@/views/News/NewsDetail"
import Issue from "@/views/News/Issue"
import HasIssue from "@/views/News/HasIssue"
Vue.use(VueRouter)

const routes = [
  {
    path: "/home",
    name: "home",
    component: Home,
  },
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/order",
    name: "order",
    component: Order,
  },

  {
    path: "/newsdetail",
    name: "newsdetail",
    component: NewsDetail,
  },

  {
    path: "/news",
    name: "news",
    component: News,
  },

  {
    path: "/issue",
    name: "issue",
    component: Issue,
  },

  {
    path: "/hasissued",
    name: "hasissued",
    component: HasIssue,
  },

  {
    path: "/tobeshipped",
    name: "tobeshipped",
    component: ToBeShipped,
  },
  {
    path: "/feedback",
    name: "feedback",
    component: FeedBack,
  },

  {
    path: "/goodsdetaillist",
    name: "goodsdetaillist",
    component: GoodsDetailList,
  },

  {
    path: "/gotalk",
    name: "gotalk",
    component: GoTalk,
  },

  {
    path: "/takephoto",
    name: "takephoto",
    component: TakePhoto,
  },

  {
    path: "/attestation",
    name: "attestation",
    component: Attesation,
  },

  {
    path: "/shopaddress",
    name: "shopaddress",
    component: ShopAddress,
  },

  {
    path: "/addaddress",
    name: "addaddress",
    component: AddAddress,
  },

  {
    path: "/paysuccess",
    name: "paysuccess",
    component: PaySuccess,
  },

  {
    path: "/search",
    name: "search",
    component: Search,
  },

  {
    path: "/wave",
    name: "wave",
    component: Wave,
  },

  {
    path: "/my",
    name: "my",
    component: My,
  },
  {
    path: "/goodsdetail",
    name: "goodsdetail",
    component: GoodsDetail,
  },
  {
    path: "/myshop",
    name: "myshop",
    component: MyShop,
  },

  {
    path: "/onlineshop",
    name: "onlineshop",
    component: OnlineShop,
  },
  {
    path: "/uploadcommoditiesd",
    name: "uploadcommoditiesd",
    component: UploadCommoditiesd,
  },
  {
    path: "/mypop",
    name: "mypop",
    component: Mypop,
  },
  {
    path: "/upload",
    name: "upload",
    component: Upload,
  },
  {
    path: "/myinformation",
    name: "myinformation",
    component: MyInformation,
  },
  {
    path: "/cart",
    name: "cart",
    component: Cart,
  },

  {
    path: "/shoplist",
    name: "shoplist",
    component: ShopList,
  },

  {
    path: "/login",
    name: "login",
    component: Login,
  },

  {
    path: "/face",
    name: "face",
    component: Face,
  },
  // {
  //   path: "/about",
  //   name: "about",
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: function () {
  //     return import(/* webpackChunkName: "about" */ "../views/AboutView.vue")
  //   },
  // },
]
// 解决导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
})

router.beforeEach((to, from, next) => {
  if (to.path === "/" || to.path === "/login") return next()
  // // 获取token
  const tokenstr = window.localStorage.getItem("UserShopInfo")
  // if (!tokenstr) return next("/")
  next()
})

export default router
